/*mNf5QZ565+3bGGQNyKuoC+hO4TZ7fJe3L0xOKK7lBhj3Sm+z93+DlZq9vvkZX6oPlgQpz8VdQ3EE
EdJpejtlBQ==*/
/**
 * 计提利息明细页签的按钮处理
 */
import constants from '../../constants/index';
import ampub from 'ampub';

const { utils: { multiLangUtils: { getMultiLangByID }, msgUtils: { showMessage } } } = ampub;

const {
	UISTATE,
	DAILY_INTEREST,
	MONTHLY_INTEREST,
	AREA: { CARD: { DEPACCRUAL_TAB_MONTH: depaccrual_tab_month, USUFRUCTASSET_AREA: usufructasset_tab } },
	CARD_BTNS: { TABLE_HEAD: { INTEREST: { DAILY_INTEREST: daily_interest_btn, MONTHLY_INTEREST: monthly_interest_btn } } }
} = constants;

export default function buttonClick(props, id) {
	const that = this;
	switch (id) {
		//日利息
		case daily_interest_btn:
			doDailyInterest.call(that);
			break;

		//月利息
		case monthly_interest_btn:
			doMonthlyInterest.call(that);
			break;

		default:
			break;
	}
}

/**
 * 启用按日计息方式
 */
function enableDailyInterest() {
	const { props: { meta, form, button, cardTable, getUrlParam } } = this;
    const status = getUrlParam('status');
    const { ADD, EDIT, BROWSE, BLANK } = UISTATE;

	// 1.表格隐藏月，显示日
	cardTable.hideColByKey(depaccrual_tab_month, MONTHLY_INTEREST);
	cardTable.showColByKey(depaccrual_tab_month, DAILY_INTEREST);

	// 2.按钮隐藏日，显示月
	button.setButtonVisible(daily_interest_btn, false);
	button.setButtonVisible(monthly_interest_btn, true);

	// 3.修改表名：计提利息明细(按天)
	let meta0 = meta.getMeta();
	meta0[depaccrual_tab_month].name = getMultiLangByID('201201504A-000062');
	meta.setMeta(meta0);

	// 4.设置表格态
    const tableStatus = [ ADD, EDIT ].includes(status) ? EDIT : BROWSE;
	cardTable.setStatus(depaccrual_tab_month, tableStatus);
}

/**
 * 启用按月计息方式
 */
function enableMonthlyInterest() {
	const { props: { meta, form, button, cardTable, getUrlParam } } = this;
    const status = getUrlParam('status');
    const { ADD, EDIT, BROWSE, BLANK } = UISTATE;

	// 1.表格隐藏日，显示月
	cardTable.hideColByKey(depaccrual_tab_month, DAILY_INTEREST);
	cardTable.showColByKey(depaccrual_tab_month, MONTHLY_INTEREST);

	// 2.按钮隐藏日、月
	button.setButtonVisible(daily_interest_btn, false);
	button.setButtonVisible(monthly_interest_btn, false);

	// 3.修改表名：计提利息明细(按月)
	let meta0 = meta.getMeta();
	meta0[depaccrual_tab_month].name = getMultiLangByID('201201504A-000057');
	meta.setMeta(meta0);

	// 4.设置表格态
    const tableStatus = [ ADD, EDIT ].includes(status) ? EDIT : BROWSE;
	cardTable.setStatus(depaccrual_tab_month, tableStatus);
}

/**
 * 按天计息方式下，展示按日计息
 */
function doDailyInterest() {
	this.setState({ isaccruedbymonth: false }, () => {
		enableDailyInterest.call(this);
		toggleDailyBtns.call(this, false);
		const deps = this.getDepaccrualCache.call(this);
		this.setDepaccrualTab.call(this, deps);
	});
}

/**
 * 按天计息方式下，展示按月计息
 */
function doMonthlyInterest() {
	this.setState({ isaccruedbymonth: true }, () => {
		enableMonthlyInterest.call(this);
		toggleDailyBtns.call(this, true);
		const deps = this.getDepaccrualCache.call(this);
		this.setDepaccrualTab.call(this, deps);
	});
}

/**
 * 是否显示日利息按钮？否则显示月利息按钮
 * 
 * @param {显示日利息按钮} showDailyBtns 
 */
function toggleDailyBtns(showDailyBtns) {
	const { props: { button } } = this;
	button.setButtonVisible(daily_interest_btn, showDailyBtns);
	button.setButtonVisible(monthly_interest_btn, !showDailyBtns);
}

export { toggleDailyBtns, enableDailyInterest, enableMonthlyInterest };

/*mNf5QZ565+3bGGQNyKuoC+hO4TZ7fJe3L0xOKK7lBhj3Sm+z93+DlZq9vvkZX6oPlgQpz8VdQ3EE
EdJpejtlBQ==*/